package com.qiku.controller;

import com.github.pagehelper.PageInfo;
import com.qiku.domin.Resource;
import com.qiku.domin.ResourceCategory;
import com.qiku.domin.ResourceVO;
import com.qiku.domin.ResponseResult;
import com.qiku.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    @PostMapping("/findAllResource")
    public ResponseResult findAllResource(@RequestBody ResourceVO resourceVO){
        PageInfo<Resource> pageInfo = resourceService.findAllResource(resourceVO);
        ResponseResult result = new ResponseResult(true, 200, "响应成功", pageInfo);
        return result;
    }


    @PostMapping("/saveOrUpdateResource")
    public ResponseResult saveOrUpdateResource(@RequestBody Resource resource){
        if (null != resource.getId() && 0 < resource.getId()){
            resourceService.UpdateResource(resource);
            ResponseResult result = new ResponseResult(true, 200, "响应成功", null);
            return result;
        }else {
            resourceService.saveResource(resource);
            ResponseResult result = new ResponseResult(true, 200, "响应成功", "");
            return result;
        }
    }

    @GetMapping("/deleteResource")
    public ResponseResult deleteResource(Integer id){
        resourceService.deleteResource(id);
        ResponseResult result = new ResponseResult(true, 200, "响应成功", "");
        return result;
    }


}
